home *** CD-ROM | disk | FTP | other *** search
- /*
- House picture
-
- This application will create a picture of a house. Each object in the picture will represent one piece of the house.
- The border of the house and the window frames are created with polygons. The door is created with a rectangle. Each object
- is added to the picture with a call to AddToPicture. The color of various objects by adding an ink to the object.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "ColorLibrary.c", "GraphicsDebugLibrary.c",
- "PictureLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
-
- • This file prints the "best" in landscape mode.
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Updated the note regarding the files needed to run.
- Updated the copyright date.
-
- ©1990 - 1996 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <Events.h>
- #include <FixMath.h>
- #include <Windows.h>
-
- #include "GraphicsLibraries.h"
- #include <GXEnvironment.h>
- #include "graphics shell.h"
-
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\pHouse Picture";
- Rect gWindowQDRect = {40, 10, 185, 275};
-
-
- //
- // gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics heap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics heap. Sounds good to me.
- //
- long gGraphicsHeapSize = 25;
-
- gxShape gOurHouse;
-
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(aWindow)
- WindowPtr aWindow;
- {
- long windowGeometry[] = {3, // number of contours
- 4, // points in frame
- 0, 0, ff(30), 0, ff(30), ff(30), 0, ff(30), // window frame
- 2, // points in vertical crossbar
- ff(15), 0, ff(15), ff(30),
- 2, // points in horizontal crossbar
- 0, ff(15), ff(30), ff(15)};
-
- long houseGeometry[] = { 7, // number of points in the house border
- 0, ff(10),
- 0, ff(30),
- ff(100), ff(30),
- ff(100), ff(10),
- 0, ff(10),
- ff(50), 0,
- ff(100), ff(10)};
-
- gxRectangle doorGeometry = {ff(45), ff(15), ff(55), ff(30)};
- gxShape windowShape, houseBorderShape, doorShape;
- gxTransform newWindowTransform;
-
- gOurHouse = GXNewShape(gxPictureType);
-
- windowShape = GXNewPolygons((gxPolygons *) windowGeometry);
- houseBorderShape = NewPolygon((gxPolygon *) houseGeometry);
- doorShape = GXNewRectangle(&doorGeometry);
-
- //
- // Set up the fillType and style for the house border
- //
- {
- gxStyle thickPen = GXNewStyle();
-
- GXSetShapeFill(houseBorderShape, gxHollowFill);
- GXSetStylePen(thickPen, ff(1));
-
- AddToPicture(gOurHouse, houseBorderShape, thickPen, nil, nil);
- GXDisposeShape(houseBorderShape);
- GXDisposeStyle(thickPen);
- }
-
- GXSetShapeFill(doorShape, gxHollowFill);
- AddToShape(gOurHouse, doorShape);
- GXDisposeShape(doorShape);
-
- //
- // We will add the window to our house four times. We move the window within the picture by creating
- // a new transform each time through the loop. We will also add an ink to each window.
- //
- { short counter;
-
- GXSetShapeFill(windowShape, gxHollowFill);
-
- for (counter = 2; counter <= 5; counter++)
- { gxTransform newTransform = GXNewTransform();
-
- GXScaleTransform(newTransform, fixed1/3, fixed1/3, 0, 0);
- if (counter <= 3)
- GXMoveTransform(newTransform, counter * ff(15) - ff(20), ff(15));
- else
- GXMoveTransform(newTransform, counter * ff(15) + ff(5), ff(15));
-
- if (counter == 2)
- { gxInk redInk = GXNewInk();
-
- SetInkCommonColor(redInk, red);
-
- AddToPicture(gOurHouse, windowShape, nil, redInk, newTransform);
-
- GXDisposeInk(redInk);
- } else if (counter == 3)
- { gxInk grayInk = GXNewInk();
-
- SetInkCommonColor(grayInk, gxGray);
- AddToPicture(gOurHouse, windowShape, nil, grayInk, newTransform);
- GXDisposeInk(grayInk);
-
- } else
- { gxInk turquoiseInk = GXNewInk();
- SetInkCommonColor(turquoiseInk, turquoise);
-
- AddToPicture(gOurHouse, windowShape, nil, turquoiseInk, newTransform);
- GXDisposeInk(turquoiseInk);
- }
- GXDisposeTransform(newTransform);
- }
- GXDisposeShape(windowShape);
- }
-
- GXMoveShape(gOurHouse, ff(25), ff(25));
- GXScaleShape(gOurHouse, fl(1.75), fl(1.75), 0, 0);
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(aWindow)
- WindowPtr aWindow;
- {
- //
- // I am not exactly sure why GX graphics is posting this notice here, but I did not want to see it. I
- // think it is a bug... I will look inot this problem before the next CD. Stay tuned to this space for coming details...
- //
- GXIgnoreGraphicsNotice(transform_viewPorts_already_set);
-
- GXDrawShape(gOurHouse);
-
- GXPopGraphicsNotice();
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(aWindow)
- WindowPtr aWindow;
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- DisposeCommonColors ();
- GXDisposeShape(gOurHouse);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(aWindow);
- }
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(aWindow)
- WindowPtr aWindow;
- {
- }